package Util
{
	
	import data.AppConfig;
	
	import datastructure.RBTreeNode;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import view.NodeCircle;

	public class DrawTree
	{
		private static var NIL:RBTreeNode = new RBTreeNode(-1);
		
		public function DrawTree()
		{
			
		}
	
		
		public static function drawNodes(root:RBTreeNode,testContainer:Sprite):void
		{
			if(root.key == -1)
				return;
			drawNodes(root.left,testContainer);
			var nodeCircleSprit:NodeCircle = new NodeCircle(root.key,root.color);
			nodeCircleSprit.x = root.OffsetX;
			nodeCircleSprit.y = root.distance * 50;
			testContainer.addChild(nodeCircleSprit);
			drawNodes(root.right,testContainer);
		}
		
		public static function drawLines(root:RBTreeNode,treeContainer:Sprite):void
		{
			if(root.key == -1)
				return;
			treeContainer.addChildAt(drawLine(root,root.parent),0);
			drawLines(root.left,treeContainer);
			drawLines(root.right,treeContainer);	
		}
		
		
		/**
		 * 画出两个节点之间的线 
		 * @param node
		 * @param parent
		 * @return 
		 * 
		 */		
		private static function drawLine(node:RBTreeNode,parent:RBTreeNode):Shape
		{
			var lineObject:Shape = new Shape();
			lineObject.graphics.clear();
			lineObject.graphics.lineStyle(2,0xff0000);
			lineObject.graphics.moveTo(node.OffsetX,node.distance * 50);
			lineObject.graphics.lineTo(parent.OffsetX,parent.distance * 50);
			return lineObject;
		}
		
		
		
		
		
		
		
		
		
		
	}
}